from cryptography.hazmat.primitives.asymmetric import rsa, padding
from cryptography.hazmat.primitives import hashes

def sign_model(model, private_key):
    """
    对模型进行签名
    :param model: 模型参数
    :param private_key: 私钥
    :return: 签名
    """
    signature = private_key.sign(
        model,
        padding.PSS(
            mgf=padding.MGF1(hashes.SHA256()),
            salt_length=padding.PSS.MAX_LENGTH
        ),
        hashes.SHA256()
    )
    return signature

# 示例
private_key = rsa.generate_private_key(
    public_exponent=65537,
    key_size=2048
)
model = b"model_weights"
signature = sign_model(model, private_key)
print(f"Signature: {signature}")